import axios from "axios";

export const baseURL = import.meta.env.MODE == "development" ? "/api/" : "https://yuhuo.online/yho-server/";
export const WebSocketURL = import.meta.env.MODE == "development" ? "ws://localhost:4000" : "wss://yuhuo.online/yho-socket";

export const request = axios.create({
    baseURL,
    withCredentials: true,
});

// 添加响应拦截器，处理429
request.interceptors.response.use(
    response => response,
    error => {
        if (error.response && error.response.status === 429) {
            alert("请求过于频繁，请稍后再试");
        }
        return Promise.reject(error);
    }
);

export interface Response<T = any> {
    status: number;
    message?: string;
    data?: T;
}